home *** CD-ROM | disk | FTP | other *** search
- /*
- * UPTIME.C - Show the time the system has been running.
- *
- * PROGRAMMER: Martti Ylikoski
- * CREATED: 30.3.1991
- */
- static char *VERSION = "Versio 1.0, Copyright (c) Martti Ylikoski, 1991" ;
- /*
- */
-
- #include <stdio.h>
- #define INCL_DOSINFOSEG
- #include <os2.h>
- #include <param.h>
- #include <paramstd.h>
-
- static char *progname, *fname ;
- extern unsigned long pflags ;
-
- ParamEntry pentry[12] = {
- "P", &ParamSetPause, 0,
- "F", &ParamSetFold, 0,
- "V", &ParamSetVerbose, 1,
- "R", &ParamSetReport, 1,
- "S", &ParamSetSubDirs, 0,
- "?", &ParamSetHelp, 1,
- "H", &ParamSetHelp, 1,
- "NOD", &ParamSetNoDefault, 0,
- "TEST", &ParamSetTest, 0,
- "Y", &ParamSetYes, 0,
- "N", &ParamSetTest, 0,
- "\0", NULL, 0
- } ;
-
- ParamBlock params = {
- "/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
- pentry
- } ;
-
- int main(int argc, char *argv[])
- {
- USHORT ret ;
- SEL ginfo, linfo ;
- GINFOSEG FAR *pgis ;
- int output ;
- unsigned long days, hours, minutes, seconds, hundredths ;
-
- progname = argv[0] ;
- days = 0L ; hours = 0L ; minutes = 0L ; seconds = 0L ; hundredths = 0L ;
- output = FALSE ;
-
- ParamHandle(¶ms, &argc, argv) ;
-
- if (pflags & PA_HELP )
- {
- printf("%s - displays the time the system has been up.\n", progname) ;
- puts(VERSION) ;
- printf("Usage: %s [/H | /? | /R ] command arguments\n", progname) ;
- puts("Where:") ;
- puts(" /R = Report mode /H,/? = Help") ;
- return( 0 ) ;
- }
-
- if (( ret = DosGetInfoSeg(&ginfo, &linfo)) != 0)
- {
- printf("%s: error in DosGetInfoSeg", progname) ;
- return(1) ;
- }
-
- pgis = MAKEPGINFOSEG(ginfo) ;
-
- seconds = pgis->msecs / 1000 ;
- minutes = seconds / 60 ;
- hours = minutes / 60 ;
- days = hours / 24 ;
- hours -= days * 24 ;
- minutes -= days*24*60 + hours * 60 ;
- seconds -= days*24*60*60 + hours*60*60 + minutes*60 ;
- hundredths -= days*24*60*60*1000 + hours*60*60*1000 + minutes*60*1000 + seconds*1000 ;
-
- if (pflags & PA_REPORT)
- {
- printf("[UPTIME]\ndays=%ld\nhours=%ld\nminutes=%ld\nseconds=%ld\n",
- days, hours, minutes, seconds) ;
- }
- else
- {
- printf("The system has been up ") ;
-
- if (days != 0)
- {
- output = TRUE ;
- printf("%ld days, ", days) ;
- }
-
- if (hours != 0)
- {
- output = TRUE ;
- printf("%ld hours, ", hours) ;
- }
-
- if (minutes != 0 || output == TRUE)
- {
- output = TRUE ;
- printf("%ld minutes, ", minutes ) ;
- }
-
- if (seconds != 0 || output == TRUE)
- {
- output = TRUE ;
- printf("%ld seconds.\n", seconds ) ;
- }
-
- // printf("%ld hundredths.", hundredths ) ;
- // printf("The system has been up %ul milliseconds\n", pgis->msecs) ;
- }
-
- return( 0 ) ;
- }
-